﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.NodeFactory;

namespace MartinsNeves.masterpages
{
    public partial class Root : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Node currentNode = Node.GetCurrent();
            if (currentNode != null)
            {
                if (currentNode.NodeTypeAlias.ToLower() == "root")
                {
                    Node nextNode = new Node();
                    foreach (Node child in currentNode.Children)
                    {
                        nextNode = child;
                        break;
                    }
                    if(nextNode.Id>0)
                        Response.Redirect(Page.ResolveUrl(nextNode.NiceUrl));
                }
            }
        }
    }
}